<!--
 * @Author: 白印潇 bai_yinxiao@163.com
 * @Date: 2023-03-20 15:31:04
 * @LastEditors: 白印潇 bai_yinxiao@163.com
 * @LastEditTime: 2023-03-22 16:25:47
 * @FilePath: /shortRent-ui/src/views/risk/illegal/components/correlationOrg.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <el-dialog title="关联公司" :visible.sync="visible" width="500px" @close="close">
    <div>
      <el-form :model="formData" ref="formData" :rules="rules" label-position="left" :inline="false" size="normal">
        <el-row :gutter="20">
          <el-col :span="24" :offset="0">
            <el-form-item label="关联车辆所属公司:" label-width="140px" prop="orgIdList">
              <el-select style="width: 300px;" v-model="formData.orgIdList[0]" filterable placeholder="请选择关联所属公司">
                <el-option v-for="(item) in companyList" :key="item.id" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

    </div>
    <span slot="footer">
      <el-button @click="close">取消</el-button>
      <el-button type="primary" @click="confim">确定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import * as illegalApi from '@/api/car/illegal';
export default {
  data() {
    return {
      visible: false,
      companyList: [],
      formData: {
        id: '',
        orgIdList: []
      },
      rules: {
        orgIdList: [
          { type: 'array', required: true, message: '请选择关联车辆所属公司', trigger: 'change' }
        ]
      }
    }
  },
  created() {
    this.getCompanyList();
  },
  methods: {
    //获取所属公司列表
    getCompanyList() {
      illegalApi.illegalAcountOrgList().then(res => {
        this.companyList = res.data;
      })
    },
    // 确定按钮
    confim() {
      this.$refs.formData.validate((valid) => {
        if (valid) {
          this.$confirm('确认关联公司吗?', '提示', {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
          }).then(() => {
            illegalApi.illegalAcountDeploy(this.formData).then(res => {
              if (res.code == 200) {
                this.close();
                this.$emit('success');
                this.$message({
                  type: 'success',
                  message: '修改成功'
                });
              }
            })
          })

        }
      });
    },
    /**
     * 显示弹框
     * @param {编辑回显的账号id} illegalQueryAccountId
     */
    show(illegalQueryAccountId) {
      // 延时处理重置数据,防止数据污染
      this.$nextTick(() => {
        this.$refs.formData.resetFields();
      });
      this.formData.id = illegalQueryAccountId;
      // 获取回显数据
      illegalApi.illegalAcountDetail(illegalQueryAccountId).then(res => {
        this.formData.orgIdList = res.data.orgIdList;
      });
      this.visible = true;
    },
    close() {
      this.visible = false;
    }
  },
}
</script>
<style lang="">

</style>
